package com.mercury.system.api.model.dto;

import com.mercury.system.api.model.entity.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Optional;

/**
 * 用户信息
 *
 * @author mercury
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserAuthDto {
    /**
     * 用户ID
     */
    private Long id;

    /**
     * 部门ID
     */
    private Long deptId;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户状态：1-有效；0-禁用
     */
    private Integer status;

    /**
     * 用户角色编码集合 ["ROOT","ADMIN"]
     */

    private List<String> roles;

    /**
     * 权限标识集合
     */
    private String[] permissions;


    public UserAuthDto(SysUser sysUser) {
        Optional.ofNullable(sysUser).ifPresent(user -> {
            this.id = user.getId();
            this.username = user.getUsername();
            this.password = user.getPassword();
            this.status = user.getStatus();
            this.roles = user.getRoles();
        });
    }
}
